using System.ComponentModel.DataAnnotations;

namespace WeatherSystem.API.Models
{

    /// <summary>
    /// 天气数据查询请求模型
    /// </summary>
    public class WeatherDataQueryRequest
    {
        /// <summary>
        /// 城市ID
        /// </summary>
        public Guid? CityId { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? StartDate { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? EndDate { get; set; }



        /// <summary>
        /// 页码（从1开始）
        /// </summary>
        [Range(1, int.MaxValue, ErrorMessage = "页码必须大于0")]
        public int Page { get; set; } = 1;

        /// <summary>
        /// 每页大小
        /// </summary>
        [Range(1, 100, ErrorMessage = "每页大小必须在1到100之间")]
        public int PageSize { get; set; } = 20;

        /// <summary>
        /// 排序字段
        /// </summary>
        public string? SortBy { get; set; } = "RecordedAt";

        /// <summary>
        /// 排序方向（asc/desc）
        /// </summary>
        public string? SortDirection { get; set; } = "desc";
    }

    /// <summary>
    /// 动态创建天气数据请求模型
    /// </summary>
    public class CreateDynamicWeatherDataRequest
    {
        [Required]
        public Guid CityId { get; set; }
        
        [Required]
        public DateTime RecordedAt { get; set; }
        
        public string? Source { get; set; }
        
        /// <summary>
        /// 动态指标数据
        /// </summary>
        public Dictionary<string, object>? Metrics { get; set; }
    }

    /// <summary>
    /// 动态更新天气数据请求模型
    /// </summary>
    public class UpdateDynamicWeatherDataRequest
    {
        public Guid? CityId { get; set; }
        public DateTime? RecordedAt { get; set; }
        public string? Source { get; set; }
        
        /// <summary>
        /// 要更新的动态指标数据
        /// </summary>
        public Dictionary<string, object>? Metrics { get; set; }
    }

    /// <summary>
    /// 分页查询结果
    /// </summary>
    public class PagedResult<T>
    {
        /// <summary>
        /// 数据列表
        /// </summary>
        public List<T> Data { get; set; } = new List<T>();

        /// <summary>
        /// 总记录数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 当前页码
        /// </summary>
        public int Page { get; set; }

        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize);

        /// <summary>
        /// 是否有下一页
        /// </summary>
        public bool HasNextPage => Page < TotalPages;

        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool HasPreviousPage => Page > 1;

        /// <summary>
        /// 构造函数
        /// </summary>
        public PagedResult() { }

        /// <summary>
        /// 构造函数
        /// </summary>
        public PagedResult(List<T> data, int totalCount, int page, int pageSize)
        {
            Data = data;
            TotalCount = totalCount;
            Page = page;
            PageSize = pageSize;
        }
    }
}